//	Company:	HTHK
//	NAME:	    ProjectCategoryServlet.java
//	TITLE:	    The maintence of ProjectCategory in Time Sheet System
//	FUNCTION:	The flow control interface of class ProjectCategory associate with the table
//	BY:	        Kodak Xu
//	DATE:	    09/12/2003
//	Update_by	Poly Li
//	Update_date	16-01-2004
// --------------------------------------------------------------
// MODIFICATION HISTORY
// --------------------------------------------------------------
//	CR Log #:  99999  BY:  XXXX   DATE:  dd/mm/yyyy
//	ERROR:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//	FIX:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// --------------------------------------------------------------
package tss.projectcategory;

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.sql.*;

import com.ffpc.sql.*;
import com.ffpc.struts.StrutsMessage;
import com.ffpc.util.DateFormatter;

import tss.common.DBServlet2;

public class ProjectCategoryServlet extends DBServlet2 
{
	@Override
	protected String perform(HttpServletRequest request,
                             HttpServletResponse response,
                             StrutsMessage message)
    throws  ServletException,
            IOException,
            SQLException,
            DataException,
            Exception
   {
      String action = new String(request.getParameter("formAction"));

      ProjectCategoryBean projectCategory = ProjectCategoryProcess.createBean();
//Modify by Poly Li     
	  projectCategory.setCompany_code(request.getParameter("company_code"));
      projectCategory.setProject_category_name(request.getParameter("project_category_name"));
//Modify by Poly Li
	  projectCategory.setComments(request.getParameter("comments"));
	
      projectCategory.setUpd_date(DateFormatter.format(this.getDate()));
      projectCategory.setUpd_by(getUser().getUser_id());

      if (action.trim().equalsIgnoreCase("Create"))
      {
         projectCategory.setCreate_date(DateFormatter.format(this.getDate()));
         projectCategory.setCreate_by(getUser().getUser_id());
        if (ProjectCategoryProcess.insert(this.getConnection(),projectCategory)>0)
            message.setMessage("Save successfully.");
        else
            message.setMessage("Save failure");
      }
      else if (action.trim().equalsIgnoreCase("Update"))
        if (ProjectCategoryProcess.update(this.getConnection(),projectCategory)>0)
            message.setMessage("Save successfully.");
        else
            message.setMessage("Save failure.");
      else if (action.trim().equalsIgnoreCase("Delete"))
        if (ProjectCategoryProcess.delete(this.getConnection(),projectCategory)>0)
            message.setMessage("Delete successfully.");
        else
            message.setMessage("Delete failure.");
      else
            message.setMessage("No action mapped!");


      return "tss/projectcategory/ProjectCategorySearch.jsp";
   }
}
